/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.frankkie.parcdroidprj;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

/**
 *
 * @author frankkie
 */
public class RouteView extends View {

  Path mPath = new Path();
  Paint paint = new Paint();
  private AttributeSet s;
  private Context c;

  public RouteView(Context c, AttributeSet s) {
    super(c, s);
    this.c = c;
    this.s = s;
    mPath.moveTo(0, -25);
    mPath.lineTo(-10, 30);
    mPath.lineTo(0, 25);
    mPath.lineTo(10, 30);
    mPath.close();
  }

  public RouteView(Context context) {
    super(context);
    mPath.moveTo(0, -25);
    mPath.lineTo(-10, 30);
    mPath.lineTo(0, 25);
    mPath.lineTo(10, 30);
    mPath.close();
  }

  @Override
  protected void onDraw(Canvas canvas) {
    System.out.println("RouteView.onDraw BEGIN");
    //canvas.drawColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLACK);

    //COMPASS
    int cx = 50;
    int cy = 50;
    paint.setAntiAlias(true);
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL);
    float[] compassV = SensorTester.compassValues;

    if (compassV != null &&
            compassV.length >= 3) {
      canvas.drawText("Compass (" + compassV[0] + "," + compassV[1] + "," + compassV[2] + ")", 90, 50, paint);
    } else {
      canvas.drawText("Compass", 100, 50, paint);
    }
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL);
    canvas.translate(cx, cy);
    if (SensorTester.compassValues != null) {
      canvas.rotate(-SensorTester.compassValues[0]);
    }
    canvas.drawPath(mPath, paint);
    System.out.println("RouteView.onDraw EINDE");

    //invalidate();
    }
}
